package com.yzt.zhuju.gift;

import com.yzt.zhuju.network.entity.gift.Gift;

import java.util.ArrayList;
import java.util.List;

/**
 * author : Irene
 * e-mail : 821970751@qq.com
 * date   : 2020/5/28 10:26
 * desc   :
 */
public class GiftSelectManager {

    public static List<GiveGiftSelectChangedObservable> giveGiftObservers = new ArrayList<>();

    public interface GiveGiftSelectChangedObservable {

        void selectGiftData( int type, Gift gift);
    }

    private GiftSelectManager() {

    }

    static class InstanceHolder {
        final static GiftSelectManager INSTANCE = new GiftSelectManager();
    }

    public static GiftSelectManager getInstance() {
        return InstanceHolder.INSTANCE;
    }

    public void registerGiveGiftChangedObservable(GiveGiftSelectChangedObservable observable) {
        if (null != observable) {
            if (!giveGiftObservers.contains(observable)) {
                giveGiftObservers.add(observable);
            }
        }
    }

    public void unRegisterGiveGiftChangedObservable(GiveGiftSelectChangedObservable observable) {
        if (null != observable) {
            giveGiftObservers.remove(observable);
        }
    }

    public void selectGiftData( int type, Gift gift) {
        for (GiveGiftSelectChangedObservable observable : giveGiftObservers) {
            observable.selectGiftData( type, gift);
        }
    }
}
